package com.example.rentingapp.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.animation.Animator;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.airbnb.lottie.LottieAnimationView;
import com.example.rentingapp.MainActivity;
import com.example.rentingapp.R;

public class IntroductoryActivity extends BaseActivity implements View.OnClickListener {
    private LottieAnimationView houseAnimationView;
    private TextView tvSkip;

    @Override
    protected int initLayout() {
        return R.layout.activity_introductory;
    }

    @Override
    protected void initView() {
        houseAnimationView = findViewById(R.id.lottie_animation);
        tvSkip = findViewById(R.id.tv_skip);
    }

    @Override
    protected void initData() {
        tvSkip.setOnClickListener(this);

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                houseAnimationView.playAnimation();
                houseAnimationView.addAnimatorListener(new Animator.AnimatorListener() {
                    @Override
                    public void onAnimationStart(Animator animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        navigateToWithFlag(MainActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {

                    }
                });
            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_skip:
                navigateToWithFlag(MainActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                break;
        }
    }
}